//
//  WZLoctionShare.m
//  ETong
//
//  Created by wanzhao on 15/11/27.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZLoctionShare.h"


@interface WZLoctionShare ()<BMKLocationServiceDelegate>

@property (nonatomic, strong) BMKLocationService *locService;

@end

@implementation WZLoctionShare


+(WZLoctionShare *)LoctionShareInstance
{
    static WZLoctionShare *instance  = nil;
    static dispatch_once_t dispatch_onces;
    if(instance  == nil)
    {
        dispatch_once(&dispatch_onces, ^{
            
            instance = [[WZLoctionShare alloc] init];
        });
    }
    return instance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        _locService = [[BMKLocationService alloc] init];
        _locService.desiredAccuracy = kCLLocationAccuracyBest;
        _locService.distanceFilter = 100;
        _locService.delegate = self;
    }
    return self;
}

/**
    开启定位服务
 */
-(void)startLocationService
{
    [_locService startUserLocationService];
}
/**
 *关闭定位服务
 */
-(void)stopLocationService
{
    [_locService stopUserLocationService];
}

/**
 *在将要启动定位时，会调用此函数
 */
- (void)willStartLocatingUser
{
    if ([self.delegate respondsToSelector:@selector(willStartLocating)]) {
        [self.delegate willStartLocating];
    }
}
/**
 *在停止定位后，会调用此函数
 */
- (void)didStopLocatingUser
{
    if ([self.delegate respondsToSelector:@selector(didStopLocating)]) {
        [self.delegate didStopLocating];
    }
}

/**
 *用户方向更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    if ([self.delegate respondsToSelector:@selector(didUpdateHeading:)]) {
        [self.delegate didUpdateHeading:userLocation];
    }
}

/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    if ([self.delegate respondsToSelector:@selector(didUpdateLocation:)]) {
        [self.delegate didUpdateLocation:userLocation];
    }
}

/**
 *定位失败后，会调用此函数
 *@param error 错误号
 */
- (void)didFailToLocateUserWithError:(NSError *)error
{
    if ([self.delegate respondsToSelector:@selector(didFailToLocateWithError:)]) {
        [self.delegate didFailToLocateWithError:error];
    }
}

@end
